﻿
Public Class Form1
    '+++++++++++++++++++++++++++++++++++ Deklarationen '+++++++++++++++++++++++++++++++++++
    '################################### Potenzen '###################################
    Dim var_F1_M_TrackBar1 As Integer
    Dim var_F1_M_TrackBar2 As Integer
    Dim var_F1_M_TrackBar3 As Integer
    Dim var_F1_M_TrackBar4 As Integer
    '################################### Potenzen '###################################

    '################################### Variablen '###################################
    Dim var_F1_Num_UpDown1 As Integer
    Dim var_F1_Num_UpDown2 As Integer
    Dim var_F1_Num_UpDown3 As Integer
    Dim var_F1_Num_UpDown4 As Integer
    '################################### Variablen '###################################

    '################################### Werte '###################################
    Dim var_A As Integer 'R
    Dim var_B As Integer 'U
    Dim var_C As Integer 'I
    Dim var_D As Integer 'P
    'bool
    Dim var_Ab As Boolean  'R
    Dim var_Bb As Boolean 'U
    Dim var_Cb As Boolean 'I
    Dim var_Db As Boolean 'P
    'Erklärung: die variablen sind allgemein gehalten um sie später auch noch für andere formeln benutzen zu können
    '################################### Werte '###################################
    '################################### Potenzen '###################################
    Dim potA As Integer
    Dim potB As Integer
    Dim potC As Integer
    Dim potD As Integer
    '################################### Potenzen '###################################

    '################################### Check Box '###################################
    Dim var_F1_M_CheckBox1 As Boolean
    Dim var_F1_M_CheckBox2 As Boolean
    Dim var_F1_M_CheckBox3 As Boolean
    Dim var_F1_M_CheckBox4 As Boolean
    '################################### Check Box '###################################
    '+++++++++++++++++++++++++++++++++++ Deklarationen '+++++++++++++++++++++++++++++++++++

    '+++++++++++++++++++++++++++++++++++ Funktionen' +++++++++++++++++++++++++++++++++++
    '################################### Button Steuerung'###################################
    '1+
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If var_F1_M_TrackBar1 > MetroTrackbar1.Minimum Then 'kopieren und in die unteren einfügen/anpassen
            var_F1_M_TrackBar1 = var_F1_M_TrackBar1 - 1
            str_1()
            If var_F1_M_CheckBox1 > 0 And var_F1_M_CheckBox1 < 999 Then
                MetroTrackbar1.Value = var_F1_M_TrackBar1
            End If
            MetroLabel1.Text = "*10^" & (var_F1_M_TrackBar1) / -1
            ToolStripStatusLabel1.Text = "Potenzen neu berechnet"
        End If
    End Sub
    '1-
    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        If var_F1_M_TrackBar1 < MetroTrackbar1.Maximum Then

            var_F1_M_TrackBar1 = var_F1_M_TrackBar1 + 1
            MetroTrackbar1.Value = var_F1_M_TrackBar1
            MetroLabel1.Text = "*10^" & (var_F1_M_TrackBar1) / -1
            str_1()
            ToolStripStatusLabel1.Text = "Potenzen neu berechnet"
        End If
    End Sub
    '2+
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If var_F1_M_TrackBar2 > MetroTrackbar2.Minimum Then

            var_F1_M_TrackBar2 = var_F1_M_TrackBar2 - 1
            MetroTrackbar2.Value = var_F1_M_TrackBar2
            MetroLabel2.Text = "*10^" & (var_F1_M_TrackBar2) / -1
            str_1()
            ToolStripStatusLabel1.Text = "Potenzen neu berechnet"
        End If

    End Sub
    '2-
    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        If var_F1_M_TrackBar2 < MetroTrackbar2.Maximum Then

            var_F1_M_TrackBar2 = var_F1_M_TrackBar2 + 1
            MetroTrackbar2.Value = var_F1_M_TrackBar2
            MetroLabel2.Text = "*10^" & (var_F1_M_TrackBar2) / -1
            str_1()
            ToolStripStatusLabel1.Text = "Potenzen neu berechnet"
        End If
    End Sub
    '3+
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If var_F1_M_TrackBar3 > MetroTrackbar3.Minimum Then
            var_F1_M_TrackBar3 = var_F1_M_TrackBar3 - 1
            MetroTrackbar3.Value = var_F1_M_TrackBar3
            MetroLabel3.Text = "*10^" & (var_F1_M_TrackBar3) / -1
            If MetroTrackbar1.Value = 0 Then
                str_1()
                ToolStripStatusLabel1.Text = "Potenzen neu berechnet"
            End If
        End If
    End Sub
    '3-
    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        If var_F1_M_TrackBar3 < MetroTrackbar3.Maximum Then

            var_F1_M_TrackBar3 = var_F1_M_TrackBar3 + 1
            MetroTrackbar3.Value = var_F1_M_TrackBar3
            MetroLabel3.Text = "*10^" & (var_F1_M_TrackBar3) / -1
            If MetroTrackbar1.Value = 0 Then
                str_1()
                ToolStripStatusLabel1.Text = "Potenzen neu berechnet"
            End If

        End If
    End Sub
    '4+
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        If var_F1_M_TrackBar4 > MetroTrackbar4.Minimum Then

            var_F1_M_TrackBar4 = var_F1_M_TrackBar4 - 1
            MetroTrackbar4.Value = var_F1_M_TrackBar4
            MetroLabel4.Text = "*10^" & (var_F1_M_TrackBar4) / -1
            str_1()
            ToolStripStatusLabel1.Text = "Potenzen neu berechnet"
        End If
    End Sub
    '4-
    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        If var_F1_M_TrackBar4 < MetroTrackbar4.Maximum Then

            var_F1_M_TrackBar4 = var_F1_M_TrackBar4 + 1
            MetroTrackbar4.Value = var_F1_M_TrackBar4
            MetroLabel4.Text = "*10^" & (var_F1_M_TrackBar4) / -1
            str_1()
            ToolStripStatusLabel1.Text = "Potenzen neu berechnet"
        End If
    End Sub
    '################################### Button Steuerung '###################################

    '+++++++++++++++++++++++++++++++++++ Funktionen '+++++++++++++++++++++++++++++++++++
    '+++++++++++++++++++++++++++++++++++ Berechnung '+++++++++++++++++++++++++++++++++++
    Private Sub str_1() 'potenzen
        var_Db = MetroCheckBox1.Checked 'vorhanden ja/nein
        var_Bb = MetroCheckBox2.Checked
        var_Ab = MetroCheckBox3.Checked
        var_Cb = MetroCheckBox4.Checked
        ber_41() 'berechnen
        MetroLabel1.Text = "*10^" & var_D 'potenzen ausgeben
        MetroLabel2.Text = "*10^" & var_B
        MetroLabel3.Text = "*10^" & var_A
        MetroLabel4.Text = "*10^" & var_C
        MetroTrackbar1.Value = var_D
        MetroTrackbar2.Value = var_B
        MetroTrackbar3.Value = var_A
        MetroTrackbar4.Value = var_C
    End Sub
    Private Sub str_2() 'werte

        var_Db = MetroCheckBox1.Checked 'vorhanden ja/nein
        var_Bb = MetroCheckBox2.Checked
        var_Ab = MetroCheckBox3.Checked
        var_Cb = MetroCheckBox4.Checked
        var_D = NumericUpDown1.Value 'werte
        var_B = NumericUpDown2.Value
        var_A = NumericUpDown3.Value
        var_C = NumericUpDown4.Value
        ber_41() 'berechnen
        NumericUpDown1.Value = var_D 'werte
        NumericUpDown2.Value = var_B
        NumericUpDown3.Value = var_A
        NumericUpDown4.Value = var_C

    End Sub
    Private Sub ber_41() 'R U I P
        If var_Ab = True And var_Bb = True Then 'A&B
            var_C = var_B / var_A
            var_D = var_B * var_C
        Else
            If var_Ab = True And var_Cb = True Then 'A&C
                var_B = var_A * var_C
                var_D = var_B * var_C
            Else
                If var_Ab = True And var_Cb = True Then 'A&D
                    If var_A * var_D > 0 Then
                        var_B = Math.Sqrt(var_A * var_D)
                        var_C = var_D / var_B
                    End If
                    StatusStrip1.Text = "durch 0 Teilen nicht möglich!"

                Else
                    If var_Bb = True And var_Cb = True Then 'B&C
                        var_A = var_B / var_C
                        var_D = var_B * var_C
                        If var_Bb = True And var_Db = True Then 'B&D
                            var_A = (var_B * var_B) / var_D
                            var_C = var_D / var_B
                            If var_Cb = True And var_Db = True Then 'C&D
                                var_A = var_D / (var_C * var_C)
                                var_B = var_A * var_C
                            Else
                                StatusStrip1.Text = "Fehler bei der Berechnung!"
                            End If
                        End If
                    End If
                End If

            End If
        End If
    End Sub
    '+++++++++++++++++++++++++++++++++++ Berechnung '+++++++++++++++++++++++++++++++++++

    '+++++++++++++++++++++++++++++++++++ Checkbox '+++++++++++++++++++++++++++++++++++
    Private Sub MetroCheckBox1_Click(sender As Object, e As EventArgs) Handles MetroCheckBox1.Click 'P
        var_F1_M_CheckBox1 = MetroCheckBox1.Checked
        var_F1_M_CheckBox2 = MetroCheckBox2.Checked
        var_F1_M_CheckBox3 = MetroCheckBox3.Checked
        var_F1_M_CheckBox4 = MetroCheckBox4.Checked
        If var_F1_M_CheckBox1 = False Then
            If var_F1_M_CheckBox2 = True And var_F1_M_CheckBox3 = False And var_F1_M_CheckBox4 = False Then
                pot_1()
                pot_2()
                ToolStripStatusLabel1.Text = "R und U Freigeschaltet"
            Else
                If var_F1_M_CheckBox2 = False And var_F1_M_CheckBox3 = True And var_F1_M_CheckBox4 = False Then
                    pot_1()
                    pot_3()
                    ToolStripStatusLabel1.Text = "R und I Freigeschaltet"
                Else
                    If var_F1_M_CheckBox2 = False And var_F1_M_CheckBox3 = False And var_F1_M_CheckBox4 = True Then
                        pot_1()
                        pot_4()
                        ToolStripStatusLabel1.Text = "R und P Freigeschaltet"
                    Else
                        If (var_F1_M_CheckBox1 + var_F1_M_CheckBox2 + var_F1_M_CheckBox3 + var_F1_M_CheckBox4 = 1) Then
                            ToolStripStatusLabel1.Text = "Eine weitere Variable Ankreuzen!"
                        Else
                            ToolStripStatusLabel1.Text = "Eine weitere Variable Ankreuzen!"
                            reset()
                            reset2()
                        End If
                    End If
                End If
            End If
        Else
            reset()
        End If
        MetroCheckBox1.Checked = var_F1_M_CheckBox1
        MetroCheckBox2.Checked = var_F1_M_CheckBox2
        MetroCheckBox3.Checked = var_F1_M_CheckBox3
        MetroCheckBox4.Checked = var_F1_M_CheckBox4
    End Sub
    Private Sub MetroCheckBox2_Click(sender As Object, e As EventArgs) Handles MetroCheckBox2.Click 'U
        var_F1_M_CheckBox1 = MetroCheckBox1.Checked
        var_F1_M_CheckBox2 = MetroCheckBox2.Checked
        var_F1_M_CheckBox3 = MetroCheckBox3.Checked
        var_F1_M_CheckBox4 = MetroCheckBox4.Checked

        If var_F1_M_CheckBox2 = False Then
            If var_F1_M_CheckBox1 = True And var_F1_M_CheckBox3 = False And var_F1_M_CheckBox4 = False Then 'U&P
                pot_2()
                pot_1()
                ToolStripStatusLabel1.Text = "R und U Freigeschaltet"
            Else
                If var_F1_M_CheckBox1 = False And var_F1_M_CheckBox3 = True And var_F1_M_CheckBox4 = False Then
                    pot_2()
                    pot_3()
                    ToolStripStatusLabel1.Text = "U und I Freigeschaltet"
                Else
                    If var_F1_M_CheckBox1 = False And var_F1_M_CheckBox3 = False And var_F1_M_CheckBox4 = True Then
                        pot_2()
                        pot_4()
                        ToolStripStatusLabel1.Text = "U und P Freigeschaltet"
                    Else
                        If (var_F1_M_CheckBox1 + var_F1_M_CheckBox2 + var_F1_M_CheckBox3 + var_F1_M_CheckBox4 = 1) Then
                            ToolStripStatusLabel1.Text = "Eine weitere Variable Ankreuzen!"
                        Else
                            ToolStripStatusLabel1.Text = "Eine weitere Variable Ankreuzen!"
                            reset()
                            reset2()
                        End If
                    End If
                End If
            End If

        Else
            reset()
        End If

            MetroCheckBox1.Checked = var_F1_M_CheckBox1
            MetroCheckBox2.Checked = var_F1_M_CheckBox2
            MetroCheckBox3.Checked = var_F1_M_CheckBox3
            MetroCheckBox4.Checked = var_F1_M_CheckBox4
    End Sub
    Private Sub MetroCheckBox3_Click(sender As Object, e As EventArgs) Handles MetroCheckBox3.Click 'R
        var_F1_M_CheckBox1 = MetroCheckBox1.Checked
        var_F1_M_CheckBox2 = MetroCheckBox2.Checked
        var_F1_M_CheckBox3 = MetroCheckBox3.Checked
        var_F1_M_CheckBox4 = MetroCheckBox4.Checked

        If var_F1_M_CheckBox3 = False Then
            If var_F1_M_CheckBox1 = True And var_F1_M_CheckBox2 = False And var_F1_M_CheckBox4 = False Then
                pot_3()
                pot_1()
                ToolStripStatusLabel1.Text = "R und I Freigeschaltet"
            Else
                If var_F1_M_CheckBox1 = False And var_F1_M_CheckBox2 = True And var_F1_M_CheckBox4 = False Then
                    pot_3()
                    pot_2()
                    ToolStripStatusLabel1.Text = "U und I Freigeschaltet"
                Else
                    If var_F1_M_CheckBox1 = False And var_F1_M_CheckBox3 = False And var_F1_M_CheckBox4 = True Then
                        pot_3()
                        pot_4()
                        ToolStripStatusLabel1.Text = "I und P Freigeschaltet"
                    Else
                        If (var_F1_M_CheckBox1 + var_F1_M_CheckBox2 + var_F1_M_CheckBox3 + var_F1_M_CheckBox4 = 1) Then
                            ToolStripStatusLabel1.Text = "Eine weitere Variable Ankreuzen!"
                        Else
                            ToolStripStatusLabel1.Text = "Eine weitere Variable Ankreuzen!"
                            reset()
                            reset2()
                        End If
                    End If
                End If
            End If

        Else
            reset()
        End If

            MetroCheckBox1.Checked = var_F1_M_CheckBox1
            MetroCheckBox2.Checked = var_F1_M_CheckBox2
            MetroCheckBox3.Checked = var_F1_M_CheckBox3
            MetroCheckBox4.Checked = var_F1_M_CheckBox4
    End Sub
    Private Sub MetroCheckBox4_Click(sender As Object, e As EventArgs) Handles MetroCheckBox4.Click 'I
        var_F1_M_CheckBox1 = MetroCheckBox1.Checked
        var_F1_M_CheckBox2 = MetroCheckBox2.Checked
        var_F1_M_CheckBox3 = MetroCheckBox3.Checked
        var_F1_M_CheckBox4 = MetroCheckBox4.Checked

        If var_F1_M_CheckBox4 = False Then
            If var_F1_M_CheckBox1 = True And var_F1_M_CheckBox2 = False And var_F1_M_CheckBox3 = False Then 'P&U
                pot_4()
                pot_1()
                ToolStripStatusLabel1.Text = "R und I Freigeschaltet"
            Else
                If var_F1_M_CheckBox1 = False And var_F1_M_CheckBox2 = True And var_F1_M_CheckBox3 = False Then 'P&R
                    pot_4()
                    pot_2()
                    ToolStripStatusLabel1.Text = "U und I Freigeschaltet"
                Else
                    If var_F1_M_CheckBox1 = False And var_F1_M_CheckBox2 = False And var_F1_M_CheckBox3 = True Then 'P&I
                        pot_4()
                        pot_3()
                        ToolStripStatusLabel1.Text = "I und P Freigeschaltet"
                    Else
                        If (var_F1_M_CheckBox1 + var_F1_M_CheckBox2 + var_F1_M_CheckBox3 + var_F1_M_CheckBox4 = 2) Then
                            ToolStripStatusLabel1.Text = "Eine weitere Variable Ankreuzen!"
                        Else
                            ToolStripStatusLabel1.Text = "Eine weitere Variable Ankreuzen!"
                            reset()
                            reset2()
                        End If
                    End If
                End If
            End If

        Else
            reset()
        End If

            MetroCheckBox1.Checked = var_F1_M_CheckBox1
            MetroCheckBox2.Checked = var_F1_M_CheckBox2
            MetroCheckBox3.Checked = var_F1_M_CheckBox3
            MetroCheckBox4.Checked = var_F1_M_CheckBox4
    End Sub
    '+++++++++++++++++++++++++++++++++++ Checkbox '+++++++++++++++++++++++++++++++++++

    Private Sub pot_1() 'Steuerung der Potenzen
        NumericUpDown1.Enabled = True
        Button1.Visible = True
        Button5.Visible = True
    End Sub
    Private Sub pot_2()
        NumericUpDown2.Enabled = True
        Button2.Visible = True
        Button6.Visible = True
    End Sub
    Private Sub pot_3()
        NumericUpDown3.Enabled = True
        Button3.Visible = True
        Button7.Visible = True
    End Sub
    Private Sub pot_4()
        NumericUpDown4.Enabled = True
        Button4.Visible = True
        Button8.Visible = True
    End Sub
    Private Sub reset()
        NumericUpDown1.Enabled = False
        NumericUpDown2.Enabled = False
        NumericUpDown3.Enabled = False
        NumericUpDown4.Enabled = False
        Button1.Visible = False
        Button2.Visible = False
        Button3.Visible = False
        Button4.Visible = False
        Button5.Visible = False
        Button6.Visible = False
        Button7.Visible = False
        Button8.Visible = False
    End Sub
    Private Sub reset2()
        var_F1_M_CheckBox1 = False
        var_F1_M_CheckBox2 = False
        var_F1_M_CheckBox3 = False
        var_F1_M_CheckBox4 = False

    End Sub

    Private Sub NumericUpDown1_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown1.ValueChanged
        str_2()
    End Sub

    Private Sub NumericUpDown2_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown2.ValueChanged
        str_2()
    End Sub

    Private Sub NumericUpDown3_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown3.ValueChanged
        str_2()
    End Sub

    Private Sub NumericUpDown4_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown4.ValueChanged
        str_2()
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class



